home *** CD-ROM | disk | FTP | other *** search
/ Magazyn WWW 1999 July / www_07_1999.iso / prog / mac / alpha / alpha.hqx / Alpha ƒ / Help / Extending Alpha < prev    next >
Text File  |  1999-04-16  |  61KB  |  1,427 lines

  1.  
  2.                     Writing New Modes, Menus and Packages
  3.  
  4.  
  5.                                               created: 97-03-03 11.44.50
  6.                                           last update: 16/4/1999 {9:27:44 pm}
  7.  
  8. Author:    Vince Darley, some pieces by Tom Fetherston and Pete Keleher
  9. E-mail:    <darley@fas.harvard.edu>
  10.   mail:    Division of    Engineering and Applied    Sciences, Harvard University
  11.         Oxford Street, Cambridge MA    02138, USA
  12.    www:    <http://www.fas.harvard.edu/~darley/>
  13.  
  14.  
  15.            Introduction
  16.  
  17. If you're writing or modifying any mode, menu or extension (collectively 
  18. known as packages) related Tcl code for use with Alpha, you should read this 
  19. document.  It also tells you how to make use of some of the features of 
  20. Vince's Additions in your mode.  These instructions pertain to all versions 
  21. of Alpha greater than or equal to 7.2.
  22.  
  23. There are two basic types of package which Alpha uses: modes, and 
  24. features.  A mode helps with editing a file for a particular purpose: 
  25. web pages use 'HTML' mode, C++ code uses 'C++' mode, LaTeX documents 
  26. use 'TeX' mode,╔ There are about 20 such modes currently available.  
  27. Features are of three types: menus, extensions and ordinary features.  
  28. A feature adds functionality to Alpha either globally (a 'global 
  29. feature') or just for particular modes (a 'mode feature').  Menus are 
  30. one type of feature used to extend Alpha.  Most modes add a menu which 
  31. is automatically attached to that mode.  Other menus are often useful 
  32. globally.  It's up to the user to decide when each feature/menu is 
  33. active.  Mode-authors can of course set the defaults for their mode.  
  34. Examples of globally useful menus are the filesets menu, the eudora 
  35. menu and the electric menu.  When you create a new menu for Alpha, you 
  36. have the option of suggesting that it is attached to particular modes, 
  37. or that it is suggested as global, or that it is global only.  General 
  38. features are organised in the same way, but don't create menus.  
  39. Finally, an extension is a simple form of feature which is either 
  40. globally active or off (it either doesn't make sense or isn't 
  41. particuarly useful to turn extensions on and off in a mode-dependent 
  42. way).  Examples of extensions are the printer choices sub-menu, or the 
  43. bib-engine (used to interact with BibTeX).  Note: a 'menu' is 
  44. something which sits in Alpha's menubar, at the top level.  A feature 
  45. or extension can create submenus which sit inside top level menus, but 
  46. these are not 'menus' in the same sense.  The main distinction is that 
  47. menus must be registered with 'alpha::menu' or 'addMenu', whereas 
  48. submenus need no special registration.
  49.  
  50. For the impatient reader: here's how to write a very simple feature 
  51. which contains one new procedure and one new key-binding (to that 
  52. procedure).  Just create a file which looks like this:
  53.  
  54.     # (auto-install) --- this line will cause Alpha to try to install 
  55.     # this pkg when this file is opened outside of Alpha's folder hierarchy
  56.     
  57.     alpha::feature myPackage 0.1 {C C++} {
  58.         # no global initialisation required
  59.     } {
  60.         # activation script
  61.         # bind the 'x' key to my procedure (not a good idea ;-)
  62.         Bind 'x' myProcedure
  63.     } {
  64.         # deactivation script
  65.         unBind 'x' myProcedure
  66.     } uninstall {this-file} maintainer {
  67.         "My Name" my@email http://webpage..
  68.     } help {
  69.         Binds the blah-key to 'myProcedure' which carries out...
  70.         
  71.         This package is only designed to do something useful in
  72.         C and C++ modes.
  73.     }
  74.     
  75.     proc myProcedure {} {
  76.         # do some cool stuff
  77.     }
  78.     
  79. Save this file on your desktop (say), and open it.  You'll see Alpha
  80. automatically opens an installation dialog, puts this file in the
  81. right place if you agreed to the installation, and rebuilds its
  82. package and tcl indices so that this package can be used next time
  83. you restart Alpha (actually with a simple package like this, you can
  84. use it straight-away).  By default this package declares it is useful
  85. for C and C++ modes, although the user could choose to activate the
  86. package globally or individually for any set of modes.
  87.  
  88. Important note: if you're writing a mode, menu or package, you should 
  89. know about the 'package index'.  Alpha keeps a cache of all startup 
  90. information, so that if you edit your 'alpha::mode ...' statement, and 
  91. quit and restart Alpha, the changes will not take effect.  You must
  92. tell Alpha to rebuild the package indices before quitting.
  93.  
  94. Alpha provides lots of cool facilities to help you write useful
  95. packages, whether they are modes, menus or extensions.  This
  96. document describes those facilities.
  97.  
  98.              Guidelines for future Tcl 8 compatibility
  99.  
  100. This section is only useful if you're concerned about making
  101. future transitions easier, and has no relevance for writing
  102. code for Alpha 7.2 at present.  However, since Alpha will be upgraded
  103. to Tcl 8 for the next major release (no date yet!), knowing some of
  104. this may save you trouble later.  It will also help you to understand
  105. how to write code which works efficiently with Tcl 8, making maximum use of 
  106. the potential speed improvements there.
  107.  
  108. When Alpha upgrades to Tcl 8, some changes to your code may be necessary, 
  109. unless you pay attention to a few simple details.  First, any proc which 
  110. contains '::' is a procedure defined inside a namespace.  Tcl 8 requires 
  111. you to declare namespaces in advance.  Hence unless Tcl 8 knows about 
  112. namespace 'A', say, defining a procedure 'proc A::blah ...'  is an error.  
  113. You should therefore include the line 'namespace eval A {}' at the 
  114. beginning of the file defining all the 'A::' procedures.  (Alpha 7.2 will 
  115. ignore these namespace commands so your code works either way)
  116.  
  117. The second guideline concerns the way namespaces actually work.
  118. Assume you have defined two procedures 'A::open' and 'A::list'.
  119. Let's say: 
  120.  
  121.     proc A::list {} { open [file join $HOME Help Changes] w ; ...}
  122.     proc A::open {} { return [list a b c] }
  123.  
  124. Then both of these procedures will fail (and may crash Alpha) if 
  125. running Tcl 8.  This is because inside the procedures we're in the 'A' 
  126. namespace and this means commands are checked first to see if they 
  127. exist inisde that namespace.  Therefore command 'open' in A::list is 
  128. not the global Tcl command 'open', rather it is the procedure A::open 
  129. (obviously not what was intended above).  Similarly 'list' in A::open 
  130. is in fact the procedure A::list.  There are two ways to resolve this: 
  131. (i) write 'list' as '::list' inside the proc (and 'open' as '::open'), 
  132. or (ii) ensure the tail end of your procedures do not clash with any 
  133. global Tcl commands.  The first option will not work in Tcl earlier 
  134. than 8.0, which means you'd have to supply two different definitions 
  135. of the procedure and use 'if {[info tclversion] < 8.0} ...'  to create 
  136. the correct one.  The second option will work without modification, 
  137. and is therefore somewhat preferable.
  138.  
  139. By following these two guidelines, your code should continue to work
  140. without any changes _at all_, when Alpha upgrades (except that your
  141. code will run 2-10 times faster!).
  142.  
  143. If you're really concerned about maximum efficiency in Tcl 8, make
  144. sure you always use '{}' with both 'if' and 'expr'.  This speeds things
  145. up with Tcl 8 due to some technical aspects of the way the Tcl compiler
  146. works (see http://www.scriptics.com for details).  For example don't
  147. write 'if [expr 1+2 == 3] ...' but rather 'if {[expr {1+2 == 3}]}'.
  148.  
  149. A very important pointer for speed in Tcl 8 is that lists are very fast.
  150. This means using 'lappend', 'lindex' etc is very quick.  There is one
  151. small point you should obey: never use 'if {$myList == ""} {...}' to see
  152. if a list is empty.  Instead use 'if {![llength $myList]} {...}'.  Until
  153. Tcl implements some good optimisation in the internal compiler (which it
  154. may never do), the former expression will slow your code down hugely when
  155. the list isn't empty.
  156.  
  157. The behaviour of [file tail] has changed slightly between 7.5 and 
  158. 8.0; with 7.5 [file tail a:b:] was "", but 8.0 returns "b".  Try to write 
  159. code which doesn't depend on this distinction.
  160.  
  161. The commands 'bind', 'menu', 'unbind' etc. and all procedures in the
  162. BackCompatibility.tcl file are obsolete.  Please do not use them.  At
  163. some point in the future they will be removed completely.  In particular
  164. you should realise that the compatibility procedures are slower than
  165. calling the correct ones (especially 'menu' --- use 'Menu' instead), so
  166. you might as well go through the effort of modernising your code now.  In 
  167. addition there have been many, many improvements and bug fixes to Alpha 
  168. since 7.0/7.1, so you'll save your end-user, yourself and the Alpha-D list 
  169. a lot of trouble if everyone is encouraged to upgrade to Alpha 7.2.
  170.  
  171.              Declaring your package to Alpha
  172.  
  173. A package must contain, preferably as its first non-comment line (this 
  174. is important), a statement like this:
  175.  
  176.     alpha::mode NAME VERSION ...
  177.     
  178.     alpha::menu NAME VERSION ...
  179.     
  180.     alpha::feature NAME VERSION ...
  181.     
  182.     alpha::extension NAME VERSION ...
  183.     
  184. (The other parameters to these commands are explained below).  The name will 
  185. identify your package, and for modes must be at most 4 characters long.  
  186. It should not contain any spaces (this limitation may be lifted in a future 
  187. version of Alpha).  The version is a string of the form 1.0.1, or 2.3b1 or 
  188. 1.4.530.1.3a5.  Modes, menus and extensions take different arguments for the 
  189. remainder of the 'alpha::' declaration line, but each ends in a script which 
  190. Alpha scans and stores for you (Alpha scans all installed files for 
  191. package declaration lines and caches this information so that at startup, 
  192. no files need be read).  For modes and menus, this script is executed 
  193. automatically at startup.  For features, there are initialisation and 
  194. activation/deactivation scripts.  An extension is a simpler form of a 
  195. feature which only has a single initialisation script (used the first 
  196. time it is activated).  Package initialization occurs in the order: modes, 
  197. menus and finally extensions.
  198.  
  199. IMPORTANT: The declaration command must not be wrapped in any 'catch' 
  200. statements.  This is necessary to allow Alpha to rebuild package 
  201. indices rapidly (note that it is no longer required to be at the 
  202. beginning of the line).  If you wish to write backwards compatible code, 
  203. try something like:
  204.  
  205.     if {[info commands alpha::extension] != ""} {
  206.         alpha::extension ...
  207.     } else {
  208.         # initialize in some old way for Alpha 6.x
  209.     }
  210.  
  211. Your package will not function properly if you don't obey the above 
  212. guidelines.  Alpha itself is considered a package, with a version
  213. number, so that your code can request a particular version of Alpha.
  214. Alpha's version number also has a patchlevel which will be updated
  215. with each Tcl-only patch release.  Hence you can write:
  216.  
  217.     alpha::package require Alpha 7.1b1
  218.  
  219. For the first Alpha 7.1 beta release, and
  220.  
  221.     alpha::package require Alpha 7.1p1
  222.  
  223. If your package actually requires some fixes from the first patch 
  224. release after the final 7.1 release.  You can similarly require 
  225. particular versions of other packages.  You should 'require' as old a 
  226. version as possible, so that you don't force users to upgrade 
  227. unnecessarily.
  228.  
  229. Note that with the advent of the new alpha:: commands, it is no longer
  230. necessary to place modes, menus and packages in their separate directories:
  231. they can go anywhere on the auto-path.  However it is more convenient to
  232. store them separately most of the time.
  233.  
  234.              The developer utilities package
  235.  
  236. You will want to download this package, since it helps with a number
  237. of developer-related tasks:
  238.  
  239. Ñ    distribution archival, compression, and uploading
  240. Ñ   creation of new modes/menu/features/extensions
  241. Ñ    colouring and hyperlinking Help files (like this one)
  242.  
  243. For anyone helping with Alpha's core distribution it also allows:
  244.  
  245. Ñ    colouring Alpha's manual, commands, readme and changes files
  246.  
  247. ===============================================================================
  248.            
  249.            Writing New Modes
  250.  
  251. To add a mode to Alpha, a file (usually ending with 'Mode.tcl') must be 
  252. created and placed in the ":Tcl:Modes" directory.
  253.  
  254. The file should begin with a construct of the following form:
  255.  
  256.     alpha::mode Perl 1.3 dummyPerl {*.pl *.ph *.pm} {
  257.         perlMenu electricBraces electricReturn 
  258.     } {
  259.         addMenu perlMenu Ñ132 Perl
  260.     }
  261.  
  262. This command is very, very important.
  263.  
  264.     alpha::mode <mode> <version> <dummyProc> <suffixes> <mode-features> <script>
  265.     
  266. defines a new mode.  When trying to switch to the Perl mode, Alpha will 
  267. attempt to execute the function 'dummyPerl'.  The suffixes allow Alpha to 
  268. automatically determine the correct mode of a newly opened file.  In this
  269. case the script contains the single command:
  270.  
  271.     addMenu <mname> ?<name>? ?<pertains to modes>?
  272.  
  273. which defines a new menu, with 'name' the visible name of the menu (names 
  274. which start with 'Ñ' indicate Alpha should use an icon resource with the 
  275. given number.  Icon number 132 is the Perl camel icon).  This menu can be 
  276. used in any mode, although by default, it is only attached to Perl mode.  
  277. 'mname' is actually a variable which contains (will contain) the real menu 
  278. name (in this case 'Ñ132').  The third argument usually contains a 
  279. single mode with which this menu is distributed.  Its use is mainly so that
  280. Alpha knows that this menu belongs primarily to this mode, so that if the user
  281. asks for information on the menu, Alpha knows to respond with 
  282. information on the mode instead (curiously Alpha wouldn't otherwise 
  283. know).
  284.  
  285. Perhaps the MOST important part of the above code is the existence of the
  286. 'dummyProc'.  When this proc is called, the result must be that all of 
  287. the mode's preferences are declared.  In other words, the dummyProc
  288. should normally be in the same file as the mode's 'newPref' declarations.
  289. This is important because almost directly after that call, Alpha expects
  290. all of the mode's preferences to be stored in the ${mode}modeVars array,
  291. which will only be true if all of the newPref commands have been evaluated.
  292. IMPORTANT subtlety: the result of calling 'dummyProc' must indeed be that 
  293. all your newPref declarations are executed.  As a result of this, the 
  294. preferences will be stored in the <mode>modeVars array, but will not yet 
  295. be copied into the global scope (i.e. the <mode>modeVars(myPref) array 
  296. element will exist, but the global var 'myPref' will not yet exist).  Once 
  297. your dummyProc returns (which generally means your mode's initialisation 
  298. and sourcing of files is complete), only then are the array entries copied 
  299. into the global scope (in the latter half of the changeMode proc).
  300.  
  301. Here is an example from Diff mode:
  302.  
  303.     alpha::mode Diff 1.0 diffMenu {*.diff} {diffMenu} {
  304.         addMenu diffMenu Ñ288
  305.         menu::insert Utils submenu 0 compare
  306.         menu::insert compare items end "windows" "files╔" "directories╔"
  307.     } uninstall {
  308.         removeFile "$pkg_file"
  309.         removeFile [file join ${HOME} Tools "GNU Diff"]
  310.     } maintainer { "Vince Darley" darley@fas.harvard.edu http://... }
  311.  
  312. The 'uninstall' and 'maintainer' sections are optional, and explained later.  
  313. Here is a more complex example for Python mode:
  314.  
  315.     # ╫╫╫╫ minalmalist mode set-up ╫╫╫╫ #
  316.     alpha::mode Pyth 0.2 dummyPython {*.py *.pyc *.pyi} PythonMenu {
  317.         addMenu PythonMenu
  318.         #To set the mode from a unix-like "#!python" first line
  319.         set unixMode(python) {Pyth}
  320.     }
  321.     # dummy proc to load this mode.  
  322.     proc dummyPython {} {}
  323.     # dummy proc to load the code to make the PythonMenu 
  324.     proc PythonMenu {} {}
  325.     # rest of mode's code follows...
  326.     
  327.     #Lets the automatic comment insertion/continuation
  328.     # routines function with this mode. 
  329.     set Pyth::commentCharacters(General) "\#"
  330.     set Pyth::commentCharacters(Paragraph) [list "## " " ##" " # "]
  331.     set Pyth::commentCharacters(Box) [list "#" 1 "#" 1 "#" 3]
  332.     
  333. The package declaration should contain all code which is necessary to 
  334. recognise a given file as belonging to that mode (hence the use
  335. of 'unixMode' for python), which will then make Alpha call the
  336. dummyProc which will auto-load the entire file.  Other information,
  337. such as the 'commentCharacters' entries above should not go in the
  338. package declaration.
  339.     
  340. Notice that there are two types of 'dummy' proc: each menu Alpha uses
  341. should have a proc of the same name associated with it.  This proc is
  342. called by Alpha _each_ time Alpha tries to insert the menu into the
  343. menubar.  The proc can be empty (as above), or could actually do
  344. something if desired.  The second kind of dummy proc is the 'mode'
  345. dummy proc, given in the 'alpha::mode' command.  Here it is called
  346. 'dummyPython'.  Alpha calls this proc each time it switches to Pyth
  347. mode.  Again the proc can do something if desired, but will usually
  348. be empty.  If both procs are empty, as above, one can of course
  349. just use one proc (called PythonMenu in this case), and replace the
  350. alpha::mode line by:
  351.  
  352.     alpha::mode Pyth 0.2 PythonMenu {*.py *.pyc *.pyi} PythonMenu
  353.  
  354. The only advantage of this approach is that it saves a small amount
  355. of memory (you can delete the 'dummyPython' proc from the file). Note that 
  356. this only holds true for modes whose Tcl code is in one file.
  357.     
  358.              Multi-file modes
  359.  
  360. Modes that consist of more than a single file should no longer use a source 
  361. statement that assumes that the other files for the mode will be in 
  362. $HOME:Tcl:Modes.  The best solution is to use Alpha's standard auto-loading 
  363. capability which will source a file when it needs a procedure which is 
  364. contained in that file.  If you must use 'source' manually, you can use 
  365. 'file dirname [procs::find someProcInThisFile]' to get the current 
  366. directory.  Your other files should also be there.
  367.  
  368. A convenient way of implementing your multi-file loading is to create
  369. procs with the same name as the file at the beginning of each file.
  370. Then to load the file you just do 'catch "filename"'.  For example
  371. if there is a proc defined 'proc perl5.tcl {} {}' at the start of
  372. the file "perl5.tcl", then I can auto-load that file by having the 
  373. following code in "perlMode.tcl" (note: actual code differs slightly):
  374.  
  375.     if {[catch perl5.tcl]} { 
  376.         alertnote "Problem loading 'perl5.tcl'" 
  377.     }
  378.  
  379. Remember, you don't necessarily need to source all your mode/pkg's files in 
  380. one go.  Tcl is designed to source files for you when they are needed (when 
  381. a procedure contained in one of them is called).  Hence you only need to 
  382. source files which are required immediately (to set up some data, variables, 
  383. menus etc.)  and not everything else.  It is usually best to have a single 
  384. file which contains all the initialization code, and let any other files be 
  385. auto-loaded as necessary.
  386.  
  387.  
  388.              Use of the term "electric"
  389.  
  390. Through out the documentation and in actual proc names, you will see the use 
  391. of the word "electric", so a note on its usage might be helpful. 
  392. "Electric" is used in the sense of "automatic, power assisted behaviour", it is 
  393. intended to save time, keystrokes, and brainpower. Such behaviour is usually
  394. invoked by certain keystrokes (determined by various preference settings).
  395.  
  396.  
  397.              Mode procs
  398.  
  399. The following procs are either required or desired for a mode to be
  400. fully functional within Alpha.
  401.  
  402. Marking Proc's:        (provide indexes into code via '{}' and "M' pop-ups)
  403.  
  404.     <mode>::parseFuncs   -- (not every mode provides this one)
  405.     <mode>::MarkFile
  406.     
  407. Info providers:        (drive & support access to source or file related info)
  408.  
  409.     <mode>::DblClick    -- usually provides term specific help
  410.     
  411.     <mode>::optionTitlebar    -- provides menu to access related files
  412.     <mode>::optionTitlebarSelect    -- action for menu selection above
  413.     
  414. electric behaviour:    (these assist formatting & and save on keystrokes)
  415.  
  416.     <mode>::carriageReturn    -- this, supported by the following two, help
  417.                             --  to keep indentation standard (indirectly 
  418.                             --  called by a carriage return).
  419.     <mode>::indentLine -- indents a line, usually by calling next proc,
  420.                        -- and then inserting spaces/tabs as appropriate.
  421.     <mode>::correctIndentation -- allows smart-paste package to function
  422.  
  423.   -- These provide electric behaviour for '{', '}', and ';' respectively.
  424.   --  Their use is primarily for languages that use '{' and '}' for code
  425.   --  blocks, and ';' as the line terminator. They are indirectly called 
  426.   --  by the key they correspond to, and then, only if a corresponding mode 
  427.   --  preference flag has been defined and set to one. 
  428.   --                      (see 'Electric braces and semicolons below)
  429.   
  430.     <mode>::electricLeft
  431.     <mode>::electricRight
  432.     <mode>::electricSemi
  433.  
  434. Have a look at a standard mode like Tcl or C++ to see what these
  435. should do.  <mode>::correctIndentation must not fail (the correct
  436. indentation always exists for a line, so Alpha expects the proc to
  437. return a number and not signal an error).
  438.     
  439.              Hooks
  440.  
  441. Do not do all that 'rename saveHook mySaveHook'... stuff.  Use 
  442. 'hook::register' instead. See the file "hook.tcl" for details, but all
  443. you need to do is add lines like these:
  444.  
  445.     hook::register saveHook modified "C" "C++"
  446.     hook::register saveHook modified "Pasc"
  447.     hook::register saveHook htmlLastModified HTML
  448.     hook::register savePostHook codeWarrior_modified "C++" "C"
  449.     hook::register savePostHook ftpPostHook
  450.     hook::register saveasHook htmlLastModified HTML
  451.  
  452. Here's the general form
  453.  
  454.     hook::register 'hook-name' 'your proc' 'mode' ?... 'mode'?
  455.  
  456. If you don't include a 'mode', then your proc will be called no
  457. matter what the current mode is.   Avoid this unless absolutely
  458. necessary.  Here are the current hooks:
  459.  
  460.     activateHook changeMode closeHook deactivateHook modifyModeFlags 
  461.     quitHook resumeHook saveasHook saveHook savePostHook suspendHook
  462.     openHook
  463.  
  464. There's also a 'mode::init' hook which will be called the first
  465. time a mode is started up.  Note that at that time, the mode exists, but its
  466. variables have not yet been made global, and its menus have not
  467. yet been inserted into the menu bar.
  468.  
  469. There's also a 'startupHook' which is called when Alpha starts
  470. up, but after all other initialization has taken place, a 'launch'
  471. hook which is called when Alpha launches another application
  472. (register with hook::register launch yourproc $sig).
  473.  
  474.              Smart mode lines
  475.     
  476. If your mode will want to be able to use the first line of a file to 
  477. determine what mode a file should be opened up in, you need to tell 
  478. alpha what word in the first line should trigger that mode:
  479.     
  480.     set unixMode(python) {Pyth} 
  481.  
  482. A good place to do this is in the body of the your mode's package 
  483. declaration "alpha::mode ╔ {╔" statement (see example for Python above).  
  484. Note that the presence of the word itself is not sufficient; it must be of 
  485. the form '#!\usr\..\python' as is common on Unix (where it tells the shell 
  486. with what application to run the script)
  487.  
  488. Note that there is already built in support for opening a file in a given 
  489. mode if the first line contains:
  490.  
  491.     -*-<mode_label>-*-
  492.     
  493. e.g.:
  494.  
  495.     -*-Tcl-*-
  496.  
  497. Also, if the first line contains:
  498.  
  499.     (nowrap)
  500.  
  501. then you will not be asked if you want to see such a file in paragraph 
  502. format simplly because the lines have gotten so long alpha thinks they 
  503. might be from an application that maintains a paragraph as one long line 
  504. and does its own wrapping internally.
  505.  
  506.  
  507.              Mode creator types
  508.     
  509. If your mode wants to declare itself as a default for files with a 
  510. particular creator, (so any file with that creator opens up in that mode) 
  511. you need to tell Alpha with an entry whoses format is like this:
  512.     
  513.     set modeCreator(<4_char_creator_code>) <mode_label>
  514.  
  515. e.g.:
  516.  
  517.     set modeCreator(McPL) Perl
  518.  
  519. A good place to do this is in the body of the your mode's package 
  520. declaration "alpha::mode ╔ {╔" statement.
  521.  
  522.              Comment characters
  523.  
  524. If your mode will want to use the standard Alpha comment/uncomment
  525. block procedures, file headers, ... you need to tell Alpha what
  526. characters are used for comments.  Rather than redefining 
  527. the procedure 'commentCharacters', you should just define the following 
  528. variables:
  529.     
  530.     set ${mode}::commentCharacters(General) [list "*" "//"]
  531.     set ${mode}::commentCharacters(Paragraph) [list "/* " " */" " * "]
  532.     set ${mode}::commentCharacters(Box) [list "/*" 2 "*/" 2 "*" 3]
  533.     
  534. where the values shown are for C++ mode.  If you do this then there is
  535. no need to mess with the commentCharacters procedure.  (In general it
  536. is best if your mode does not need to redefine procedures in Alpha's core).
  537.  
  538.              Paragraph definitions
  539.  
  540. Paragraph filling.  You can set the variables:
  541.  
  542.     set ${mode}::startPara {^(.*\{)?[ \t]*$}
  543.     set ${mode}::endPara {^(.*\})?[ \t]*$}
  544.  
  545. to customize your mode's paragraph definition.  The above example's regular 
  546. expressions (third 'word') are for Tcl code.
  547.  
  548. Alpha uses these to determine what it should act on when it is requested to 
  549. re-wrap, make a selection or navigate with respect to paragraphs.  
  550.  
  551. Note that currently the wrapping routines take no notice of code formatting 
  552. rules and are limited utility outside of the 'Text' mode.  The only proc's 
  553. that use these are found in "textFill.tcl".
  554.  
  555.              Electric braces and semicolon
  556.  
  557. If your mode uses electric '{', '}', ';' (i.e. characters that end the 
  558. current line and indent the next one automatically) you need to define 
  559. a few procedures: '${mode}::electricLeft', '${mode}::electricRight' 
  560. and '${mode}::electricSemi' which will be called automatically (you do 
  561. NOT need to bind anything to the keys).  If you do not define these 
  562. procedures, Alpha will use a default electric procedure which works 
  563. pretty well for C, Perl and Java code.
  564.  
  565. Of course the user needs to turn on the electric functionality for
  566. your mode.  (Activate by default by including 'electricBraces' in 
  567. your list of mode features in the alpha::mode command).
  568.  
  569. Do not bind to '{', '}' or ';' if you want these to be electric. Alpha
  570. will automatically call your mode's procedures if they are named
  571. correctly.
  572.  
  573.              Option-click-titlebar menu
  574.  
  575. If your mode has a specific 'opt-titlebar-click' menu, you need to
  576. define the procedures:
  577.     
  578.     proc C++::OptionTitlebar {} {
  579.         # returns list of items for the menu
  580.     }
  581.     proc C++::OptionTitlebarSelect {item} {
  582.         # carries out the mode-specific action when 'item' is selected.
  583.     }
  584.  
  585.              Electric code templates
  586.     
  587. If you mode wants to insert text into the window which contains template 
  588. stops (usually bullets 'Ñ' in Alpha), so that the user can move from
  589. one to the next using the standard Alpha template packages (Alpha comes with 
  590. a basic one, and more sophisticated ones build upon the same 
  591. infrastructure), the you should insert template text with:
  592.  
  593.     elec::Insertion "blah blah ÑÑ blah blah"
  594.  
  595. This is a simple example with a single template stop.  Template stops are 
  596. noted with a pair of bullets (even though only one appears in the text).  
  597. You can place between the pair of bullets some more information about the 
  598. template stop, for instance:
  599.  
  600.     elec::Insertion "while \{ÑconditionÑ\} \{\r\tÑwhile bodyÑ\r\}\rÑÑ"
  601.  
  602. would be useful to insert a typical Tcl 'while' loop.  The template
  603. packages can prompt the user with the explanatory text making code 
  604. entry a little bit easier.
  605.  
  606. The 'elec::Insertion' routine works just like 'insertText' except it treats 
  607. any item ÑPROMPTÑ as a template stop called 'PROMPT'.  This procedure takes 
  608. a variable number of arguments, just like 'insertText'.  It has one further 
  609. side-effect.  If there are any stops in the block, then the cursor is 
  610. positioned at the first such stop.  Hence you don't need to do this: set p 
  611. [getPos] ; insertText "blah..."  ; goto $p ; nextTabStop Instead you just do 
  612. 'elec::Insert "blah..."'.  Note that the procedure 'nextTabStop' no longer 
  613. exists.  Use "ring::+", "ring::-" etc.  to move amongst tab stops.  The 
  614. basic Alpha distribution contains only basic template support.  Install 
  615. Vince's Additions to extend this support to persistent stops, with 
  616. user-prompting in the text or status bar,...  You don't have to change your 
  617. code to take advantage of the features of V'sA. It comes for free if you use 
  618. 'elec::Insertion' etc.
  619.  
  620. If you wish to use electric templates, avoid binding anything to the 'tab' 
  621. key or the 'j' key (also opt-tab, cmd-tab,╔).  Such bindings may conflict
  622. with the electric bindings.
  623.  
  624. To use electric templates, you'll want to add electricTab to your
  625. list of default mode-features (or you can leave it for the user to
  626. activate).  If your mode never wants the Tab key to indent, then 
  627. define a dummy '<mode>::indentLine' proc which is empty: 
  628. 'proc <mode>::indentLine {} {}'.
  629.  
  630.              Electric return
  631.  
  632. This allows pressing return to indent correctly for the following line 
  633. so you may begin typing immediately.  To use this simply list this 
  634. package in your mode's 'mode-features' list and, do _not_ bind to the 
  635. return key.
  636.  
  637.              Automatic indentation
  638.  
  639. Two variables are associated with a window's indentation scheme: 
  640. 'indentationAmount' and the window's tab-size (which can be read
  641. with 'getWinInfo' or 'text::getTabSize').  If you are writing a custom 
  642. indentation routine, the procedure 'indent::setup' will be useful 
  643. to handle all these choices for you.  Look at the relevant section
  644. of "globals.tcl" to see what that procedure sets up for you.  Most
  645. people user either tab-size = indentation-amount = 4 spaces, OR
  646. tab-size = 8, indentation-amount = 4 spaces.  These cases are quite
  647. different, and it's nice if your mode allows the user to work with
  648. their preferred setup.
  649.  
  650.              The marks menu
  651.  
  652. Each mode has a procedure <mode>::MarkFile which is called to create the
  653. popup 'M' menu of marks.  There is a global flag 'quietlyClearMarks'
  654. which is set to 1 which dictates that the marks should be rebuilt
  655. without prompting the user as necessary.  You can add a mode-pref
  656. to over-ride this if you want.
  657. Just what text-patterns are used to trigger the formation of a 'namedMark' 
  658. (kept in the resource fork), its name, text position and extent, and the 
  659. order in which they are present in the menu, is all determined by the 
  660. <mode>::MarkFile your procedure.
  661.  
  662. For computer language editing modes, the common convention was to create an 
  663. index by routine names for each routine defined in the file, and to present 
  664. it in alphabetical order. The more current convention is to either 
  665. hardwire, or present the user with the option of listing the routine names 
  666. in the order in which they were defined in the file, indented under the 
  667. name of the code section in which it was defined. 
  668.  
  669. The Tcl mode is a good example of the above, by default the defined Tcl 
  670. proc's are presented in alphabetical order.  However if you check the 
  671. 'StucturalMarks' flag in Tcl's mode preferences, you get an index with the 
  672. above format (after regenerating the index via the 'MarkFile' menuitem).  
  673. If you organize your Tcl code into sections of logically or functionally 
  674. related proc's, and then give them a short header by using the 
  675. 'InsertDivider' option under the Tcl Menu, you have an index that can be 
  676. used to quickly get to a procedure when remember its position or 
  677. functionality more than you do its exact name.
  678.  
  679. Of course, it is still often the case that you remember the name and just 
  680. want to get to it quickly via an alphabetical index, so modes that use the 
  681. above scheme usually provide an alphabetical listing via the '{}' popup, 
  682. which is located right above the 'M' popup (see next topic).
  683.  
  684. Power User tip: cmd-clicking anywhere in a window's titlebar (except the 
  685. exact center), or in the "bevel'ed frame" will give you the same menu as 
  686. the 'M' popup. Using the sides of the window lets you access a particular 
  687. area of the menu quicker as you can cmd-click in the approximate location 
  688. of the index you want to go to. Additionally, if the window is flush 
  689. against the lefthand edge of your monitor, it is easier to 'crash' your 
  690. cusor into that edge and summon up the mark menu than it is to hit a eight 
  691. inch square button.
  692.  
  693.              The '{}' popup menu
  694.  
  695. This popup menu can be put to whatever use the mode author wants. If your 
  696. are useing the scheme mentioned in the above section, it is good to use 
  697. this popup to present an alphabetical listing of the routines. Some modes 
  698. add extras such as indicating the number of arguments a routine expects 
  699. (see Tcl), whether a argument is a 'reference' or a 'value' pass (see the 
  700. M2, i.e. modula mode) or anything else that might be useful. Languages that 
  701. use multi-part (qualified) identifiers may name the first part of a group 
  702. of indentifiers and indent the rest of the identifiers that share that 
  703. first part under it.
  704.  
  705. Power user tip: cmd-opt-<K> will put up a listpick dialog of the indexes 
  706. under the '{}' popup, as this is usually alphabetical you can type the 
  707. starting letters of the index you want to go to. (note: see 'Emacs Help' 
  708. for some other tips to navigate any scrolling list dialog box.)
  709.  
  710.  
  711.  
  712.              <mode>Completions.tcl
  713.  
  714. Each mode can have a completions file for use by the 'elecCompletions' 
  715. package (part of Vince's Additions or available separately).  To use
  716. this, place the appropriate definitions in a file called 
  717. '<mode>Completions.tcl'.  The installer will place such files in the 
  718. 'Completions' directory automatically (provided you don't put them in 
  719. a sub-folder of your distribution), and they will also be sourced
  720. automatically the first time a file opens in your mode.  There is
  721. therefore no need for you to source the file yourself.
  722.  
  723. ===============================================================================
  724.  
  725.            Writing new menus
  726.  
  727. New menus are placed in ":Tcl:Menus", and contain a start-up
  728. section of much the same form as a mode or feature:
  729.  
  730.     alpha::menu ftpMenu    0.3 global "Ñ141" {
  731.         # One-time initialisation script 
  732.         
  733.         # here we do nothing
  734.     } {
  735.         # Activation script
  736.         
  737.         # here we do the standard thing of calling the menu proc
  738.         ftpMenu
  739.     } {
  740.         # Deactivation script
  741.     }
  742.     # proc ftpMenu to auto-load
  743.     proc ftpMenu {} {}
  744.  
  745. The 'global' parameter tells Alpha that this menu isn't associated with
  746. any particular mode (otherwise you can replace 'global' by a list of 
  747. modes possibly including the global keyword, e.g. {global WWW HTML}).
  748.  
  749. Older versions of Alpha used to call a procedure with the same name
  750. as the menu (here 'ftpMenu') automatically whenever the menu was to
  751. be inserted.  The newer setup is a bit more verbose, but puts more
  752. control in your hands.
  753.  
  754. NOTE: If all you want to do is add a submenu to an already existing
  755. menu, go to the section 'Adding Items to Global Menus': you don't
  756. need the 'alpha::menu' statement, but actually need to write a 
  757. feature using 'alpha::feature'.
  758.  
  759. A menu-package is a set of code which builds and handles a standalone menu 
  760. which the user may choose as a global menu.  Examples are the ftpMenu, 
  761. filesetMenu, voodooMenu, internetConfigMenu, colorMenu and eudoraMenu (in 
  762. fact this last item, since it has a mode associated with it, could in fact 
  763. be rewritten as a mode with attached menu).  
  764.  
  765. Note: as of Alpha 7.1, you should use the command 'Menu -n ...' to build 
  766. menus, not 'menu -n ...'
  767. ===============================================================================
  768.  
  769.            Writing new features or extensions
  770.  
  771. An extension is a package which can be turned on once and then left 
  772. alone.  Something which requires turning on/off for different modes is 
  773. a feature.  In fact an extension is just implemented as a simple form 
  774. of feature.  A new extension must provide at the very least the 
  775. following line, preferably as the first non-comment line of one of its 
  776. files:
  777.  
  778.     alpha::extension 'NAME' 'VERSION'
  779.     
  780. It is better, if possible, if the extension can provide a small script to 
  781. carry out initialisation (which occurs when Alpha starts up, if the user
  782. has turned the package on).  If provided Alpha will use that script 
  783. rather than sourcing the entire extension file.  This means Alpha will
  784. start up more quickly.  Such a script is given by the following line:
  785.  
  786.     alpha::extension 'NAME' 'VERSION' 'SCRIPT'
  787.     
  788. A feature is more sophisticated and takes arguments of the following 
  789. form:
  790.  
  791.     alpha::feature 'NAME' 'VERSION' 'LIST OF MODES/GLOBAL' \
  792.       'INIT SCRIPT' 'ACTIVATE SCRIPT' 'DEACTIVATE SCRIPT'
  793.     
  794. Here is an example from the 'bibtexEngine' package:
  795.  
  796.     alpha::extension bibtexEngine 1.8 {
  797.         eventHandler GURL GURL GURLHandler
  798.     }
  799.  
  800. Here we didn't bother to turn the feature on and off, since its 
  801. initialisation was so trivial, and it won't interfere with other 
  802. modes at all.  Here's a more complex example:
  803.  
  804.     alpha::feature latexMathbb 1.0 {TeX Bib} {
  805.         newPref variable blackboardBoldSymbols "QZRN" TeX TeX::adjustMathbb
  806.         hook::register mode::init TeX::adjustMathbb TeX
  807.     } "" ""
  808.  
  809. We didn't bother with activation deactivation, since the definitions 
  810. don't take effect in other modes.  The simple 'extension' and 
  811. 'feature' commands make it very, very easy to extend Alpha's 
  812. functionality without messing with the user's preferences file, 
  813. without creating any '...+.tcl' extension files and without a complex 
  814. installation process.  Alpha simply maintains a database of all 
  815. 'extension' scripts, and evaluates at startup all scripts for 
  816. extensions which the user has activated.
  817.  
  818.            Writing new extensions (keyboard caveats)
  819.  
  820. Writers of any package for Alpha should pay some attention to the 
  821. problems which can arise with international keyboards.  Some bindings
  822. are simply not available on some keyboards.  For instance, on some
  823. keyboards, you need to use 'shift' to get the key '\' (unlike 
  824. american keyboards where it is a single keypress).  On such a keyboard
  825. there is no distinction between 'cmd-\' and 'shift-cmd-\'.  There is
  826. no simple workaround for this problem.
  827.  
  828. Possibilities are: (i) check the current keyboard definition and adjust
  829. bindings appropriately (based upon user feedback, presumably). (ii) let
  830. the bindings be user-definable either by using 'newPref binding' to
  831. define things, or by using a menu-scheme such as is used by HTML mode.
  832.  
  833.            Technicalities of different menu/feature/extensions
  834.  
  835. Menus and features and extensions are all treated in the same way by
  836. Alpha.  However each will have different associated information which
  837. will determine whether/in what section it appears in a dialog box.
  838. All this information is stored in the index::feature array.  
  839.  
  840. ...to be continued...
  841.  
  842. ===============================================================================
  843.            
  844.            Package preferences
  845.  
  846. Alpha stores preferences in three different places:
  847.  
  848. 1)    Global preferences are stored in the global->preferences menu, and
  849. are for variables/flags which maintain a value at the global scope.
  850.  
  851. 2)  Mode preferences are stored in the mode->preferences╔ item, and
  852. are for variables/flags which are stored in a mode array, but are transfered 
  853. into global scope when that mode is active (and hence temporarily override 
  854. any global preferences with the same names)
  855.  
  856. 3)  Packages may add to the global/mode preferences as they desire.  They 
  857. may also store preferences in their package array '${pkg}modeVars(╔)'.  Such
  858. variables/flags are never transfered into the global scope.  Menu items to 
  859. edit a package's preferences should be placed in the 'global' menu, unless 
  860. they are global/mode prefs which should be added to Alpha's default 
  861. routines for use by the standard Alpha dialogs.  There is a standard proc
  862.  
  863.     package::addPrefsDialog Mypkg
  864.     
  865. which you can use to add an item to the global menu which will bring
  866. up the standard dialog to edit the contents of your '${pkg}modeVars(╔)'
  867. array.
  868.  
  869.              Adding to the core prefs dialogs
  870.  
  871. If you wish to add items to any of the core preferences pages (Backups,
  872. Electric, Miscellaneous,...), you can do that like this:
  873.  
  874.     lunion varPrefs(Electric) var1 var2
  875.     lunion flagPrefs(Electric) flag1 flag2
  876.  
  877. All non-registered global preferences are added to the Miscellaneous page,
  878. so there is no need to do that automatically.  Make sure you don't add
  879. too much to any of these pages, because they will become too large to
  880. display correctly!
  881.  
  882. You can also add new core preferences pages.  All you have to do is create
  883. a new 'flagPrefs' entry (Alpha uses the command 'array names flagPrefs' to
  884. list the different pages):
  885.  
  886.     lunion flagPrefs(NewPage) flag1
  887.     
  888. Only add such pages if your package really does merit it; otherwise you're 
  889. better off just add a new global preferences dialog in the global menu.
  890.     
  891.              Defining a package's flags and variables
  892.  
  893. Preferences for a mode or package are defined as follows:
  894.  
  895.     # description of the preference
  896.     newPref type name {val 0} {pkg "global"} {pname ""} \
  897.         {options ""} {subopt ""}
  898.  
  899. Define a new preference variable/flag.
  900.  
  901. 'type' is one of:
  902.   'flag' (on/off only), 'variable' (anything), 'binding' (key-combo)
  903.   'menubinding' (key-combo which works in a menu), 'file' (input only),
  904.   'io-file' (either input or output)
  905.   
  906. 'name' is the var name, 
  907.  
  908. 'val' is its default value (which will be ignored if the variable
  909. already has a value)
  910.  
  911. 'pkg' is either 'global' to mean a global preference, or the name 
  912. of the mode or package (no spaces) for which this is a preference.
  913.  
  914. 'pname' is a procedure to call if this preference is changed by
  915. the user (no need to setup a trace).  This proc is only called
  916. for changes made through prefs dialogs or prefs menus created by
  917. Alpha's core procs.  Other changes are not traced.
  918.  
  919. Depending on the previous values, there are two optional arguments
  920. with the following uses:
  921.  
  922. TYPE:
  923.  
  924. variable:
  925.  
  926. 'options' is a list of items from which this preference takes a single
  927. item.
  928. 'subopt' is any of 'item', 'index', 'varitem' or 'varindex' or 'array', where
  929. 'item' indicates the pref is simply an item from the given list
  930. of items, 'index' indicates it is an index into that list, and
  931. 'var*' indicates 'items' is in fact the name of a global variable
  932. which contains the list. 'array' means take one of the values from an array.
  933. If no value is given, 'item' is the default
  934.  
  935. binding:
  936.  
  937. 'options' is the name of a proc to which this item should be bound.
  938. If options = '1', then we bind to the proc with the same name as
  939. this variable.  Otherwise we do not perform automatic bindings.
  940.  
  941. 'subopt' indicates whether the binding is mode-specific or global.
  942. It should either be 'global' or the name of a mode.  If not given,
  943. it defaults to 'global' for all non-modes, and to mode-specific for
  944. all packages.  (Alpha tests if something is a mode by the existence
  945. of modeMenus($mode))
  946.  
  947. menubinding:
  948.  
  949. menubindings are like bindings, but they don't have any automatic
  950. binding capabilities, and are restricted to key-sequences which the
  951. MacOS allows in menus.  Here is an example of how one might declare
  952. the 'QuickFind(Regexp)' dynamic pair using a menubinding pref:
  953.  
  954. declare the binding:
  955.  
  956.     ╟Alpha ─╚ newPref menubinding quickFind/quickFindRegexp <B/S
  957.     
  958. edit it if we like with:
  959.  
  960.     ╟Alpha ─╚ dialog::getAKey quickFind/quickFindRegexp <B/S
  961.     
  962. show the menu sequence if we like:
  963.     
  964.     ╟Alpha ─╚ menu::bind quickFind/quickFindRegexp -
  965.     <S<E<B/SquickFind <S<I<B/SquickFindRegexp
  966.     ╟Alpha ─╚ 
  967.  
  968. add it to a menu:
  969.  
  970.     ╟Alpha ─╚ eval menu::insert Search items end \
  971.         [menu::bind quickFind/quickFindRegexp -]
  972.     
  973. Have a look at the search menu.  It has a new dynamic item at the bottom!
  974.  
  975. Note that if you place a comment (one or more lines) just before the
  976. 'newPref' statement, it is scanned and stored by Alpha in a cache.  It
  977. can then be used to explain to the user what each preference does when
  978. the user selects 'describe mode' or presses the 'Help' button in a 
  979. preference dialog.
  980.  
  981.            Declaring help text for your preferences
  982.  
  983. Alpha has the ability to extract descriptive text for your preference
  984. items automatically, provided they are declared using 'newPref', and
  985. that you follow these guidelines.
  986.  
  987. If there is a comment (a line starting with '#') on the line/lines 
  988. preceding the newPref command, Alpha will (when it rebuilds the package 
  989. indices) store the text in that line/lines and use it to display helpful 
  990. information for that preference.  For example if you hit the 'help' button 
  991. in a dialog, Alpha will display this information.  Furthermore, in the 
  992. forthcoming Alpha 8.0, this information will be used for balloon help in 
  993. the prefs dialog related to your package/mode, provided you use the 
  994. standard mechanisms for declaring your mode/menu/feature/extension and you 
  995. use the standard preference mechanism supplied.  The format of the comment
  996. lines is simple for all except basic flags (newPref flag ...).  These will 
  997. display a different help text in balloons depending on their state.  There 
  998. are four possible states, although Alpha only really uses the first and 
  999. third such states at present.  The first state is the 'unchecked' state, 
  1000. and the third the 'checked' state.  You declare separate help text for the 
  1001. four possible states like this:
  1002.  
  1003.     # it is unchecked|it is dimmed|it is checked|it is checked and dimmed
  1004.     newPref flag myFlag ...
  1005.  
  1006. In fact all help items have four possible states, although you will 
  1007. usually not notice the other possibilities.  As you can see, Alpha uses '|' 
  1008. to separate the different pieces of text.  Currently a typical help text 
  1009. for a checkbox item should probably just look like this: 
  1010.  
  1011.     # To use a solid rectangular cursor, click this box||To use a thin 
  1012.     # vertical cursor, click this box.
  1013.     newPref flag blockCursor 0
  1014.  
  1015. Notice the syntax of the two messages.  Apple's interface guidelines
  1016. give some advice for balloon help which you should follow for two 
  1017. reasons: first, it's good advice for writing balloons, and second,
  1018. Alpha assumes your messages are of the above form to use the text
  1019. effectively both for balloons, and for descriptive text.  Alpha will
  1020. automatically convert the above to:
  1021.  
  1022.     Block Cursor: To use a solid rectangular cursor, turn this item on.  To
  1023.     use a thin vertical cursor, turn this item off.
  1024.  
  1025. which is used in the descriptive dialogs Alpha sometimes provides.  This 
  1026. advice is of greatest importance for 'flag' preference items, since they
  1027. require two separate on/off balloon help texts.  Other items currently
  1028. just expect one piece of text.  Each text item should be no longer than
  1029. 255 characters.  The simplest balloon help methods impose this constraint
  1030. (in principle it could be relaxed, by using the more complex help methods
  1031. inside Alpha, but it doesn't seem necessary).
  1032.  
  1033. A similar mechanism will soon be available for menus.
  1034.     
  1035.            Adding items to global menus
  1036.  
  1037. Using 'addMenuItem' is a bad idea, since many menus are dynamically
  1038. rebuilt and such items will be lost.  Furthermore, addMenuItem does
  1039. not work if you want to add dynamic items or sub-menus.  Also
  1040. creating a menu directly using 'Menu -n Name {list of items}' is
  1041. generally a bad thing to do when using Alpha version 7.0 or newer.
  1042.  
  1043. The solution to these problems is to use the following calls:
  1044.  
  1045.     menu::buildProc 'nameOfMenu' 'nameOfIts_build-proc' 
  1046.     menu::insert 'nameOfMenu' 'type' 'where' 'menuItem' ?menuItem...?
  1047.  
  1048. For technical reasons, if you use both types of call, always add the procs 
  1049. first.  You can add any list of menuItems using the latter of these two calls.  
  1050. The first registers a procedure which will be called to build a given menu.
  1051.  
  1052. Menus must be rewritten to support this new feature.  Currently all 
  1053. global menus File...Config support it, and several modes: Tcl, Perl, 
  1054. TeX.
  1055.  
  1056.              menu::buildProc
  1057.  
  1058. This proc registers a procedure to be the 'build-proc' for a given menu 
  1059. (tech note: just adds the build-proc to the "menu_build_procs" global array 
  1060. with the given menu's name as its index).  The build-proc procedure can do 
  1061. one of two things:
  1062.  
  1063. i) build the entire menu, including evaluating the 'Menu ...' command.
  1064. In this case the build proc should return anything which doesn't
  1065. begin 'build ...'  
  1066.  
  1067. If the proc returns anything beginning with 'Menu ..' that returned 
  1068. string is evaluated, but no insertions can take place.
  1069.  
  1070. ii) build up part of the menu, and then allow pre-registered menu
  1071. insertions/replacements to take-effect.  In this case the procedure
  1072. should return a list of the following (listed by index in the list):
  1073.  
  1074. 0: "build"
  1075. 1: list-of-items-in-the-menu
  1076. 2: menu procedure to call when an item is selected.  If nothing is given,
  1077. or if '-1' is given, then we don't have a procedure.  If "" is given,
  1078. we use the standard 'menu::generalProc' procedure.  Else we use the
  1079. given procedure.
  1080. 3: list of submenus which need building.
  1081. 4: over-ride for the name of the menu.
  1082.  
  1083. Here is an example of what gets returned by "menu::globalBuild", the 
  1084. build-proc for the menu named "global" (see Config:Global:):
  1085.  
  1086.         ╟Alpha ─╚ menu::globalBuild
  1087.         0:    build 
  1088.         1:    {
  1089.                 /p<U<BmenusAndFeatures╔ 
  1090.                             {Menu -n preferences {}} 
  1091.                 editPrefsFile 
  1092.                 (- 
  1093.                 compareWindowsPrefs╔ 
  1094.                 newDocumentPrefs╔ 
  1095.                 (- 
  1096.                 specialKeys╔ 
  1097.                 listGlobalBindings 
  1098.                 listPackages 
  1099.                 listAllBindings 
  1100.                 listFunctions 
  1101.                 (- 
  1102.                 rebuildPackageIndices
  1103.             } 
  1104.         2:    menu::globalProc 
  1105.         3:    preferences
  1106.         
  1107.         Note: the above output was reformated and numbered to make its structure 
  1108.         explicit, also note that any additions to what you see in 'Config:Global:' 
  1109.         are due to calls to "menu::insert".
  1110.  
  1111. You must register the build-proc before attempting to build the menu (i.e. 
  1112. call menu::buildProc.  
  1113.  
  1114. Once registered, any call of 'menu::buildSome <name of your menu>' will 
  1115. build your menu.
  1116.  
  1117.              menu::insert
  1118.  
  1119. nameOfMenu, type, where, then list of menuItems.  Here, type can be, either 
  1120. 'items', or 'submenu'.
  1121.  
  1122. Add given items to a given menu, provided they are not already there.
  1123. Rebuild that menu if necessary.
  1124.  
  1125. There are also procs 'menu::removeFrom' which does the opposite of
  1126. this one, and 'menu::replaceWith' which replaces a given menu item
  1127. with others.
  1128.  
  1129. There is a difference between 'menu::insert Utils submenu 2 compare' and 
  1130. 'menu::insert Utils items 2 [list Menu -n compare {}]'.  The former 
  1131. registers the submenu as a submenu which will be built automatically by a 
  1132. call to 'menu::buildSome' each time the parent menu is rebuilt, the latter 
  1133. does no such thing.  You will, therefore normally wish to use the first 
  1134. form, but occasionally there will be situations when the latter would be 
  1135. better.
  1136.  
  1137. Here is a simple example:
  1138.  
  1139.     alpha::extension compareWindows 0.1 {
  1140.         Bind 0x32    <X> compare::windowsInPlace
  1141.         Bind '1'  <X> compareOpt
  1142.         Bind 0x32    <sX> compareNext
  1143.         Bind 0x12    <sX> compareOptNext
  1144.         menu::insert Utils submenu 2 compare
  1145.         menu::insert "compare" items end windowsInPlace
  1146.     }
  1147.  
  1148. We first add a submenu after the second item in the Utils menu, called
  1149. 'compare', and then add to the end of that compare menu. This code works 
  1150. whether the package is active at startup or not.  Here is a more 
  1151. complex example:
  1152.  
  1153.     alpha::extension documentProjects 1.2 {
  1154.         alpha::package require elecCompletions
  1155.         alpha::package require newDocument
  1156.         menu::buildProc "Current Project" Docproj::currentMenu
  1157.         menu::insert global items end \
  1158.             "documentProjectPrefs╔" "userDetails╔" \
  1159.             "<E<SremoveDocumentTemplate╔" "<S<BeditDocumentTemplate╔" \
  1160.             "<SnewDocumentTemplate╔" \
  1161.             "<E<SremoveProject╔" "<S<BeditProject╔" "<SnewProject╔"
  1162.         menu::insert global submenu end {Current Project}
  1163.         newPref binding updateFileVersion "/f<U" Docproj
  1164.         menu::insert fileUtils items end \
  1165.             "showInFinder" \
  1166.             "(-" \
  1167.             "updateDate" \
  1168.             "[menu::bind DocprojmodeVars(updateFileVersion) -]"
  1169.         lunion elec::MenuTemplates "createHeader" "newDocument"
  1170.         menu::insert elec items end \
  1171.             {Menu -n functionComments -p menu::fileUtils {
  1172.             "/efunctionComment"    
  1173.             "/e<IfunctionCommentSimple" 
  1174.             "/e<OfunctionCommentWithAuthor" 
  1175.             "/e<UfunctionCommentUpdate" 
  1176.         }}
  1177.         set newDocument::handlers(documentProjects) Docproj::newHandler
  1178.     }
  1179.  
  1180. The 'documentProjects' package adds items to many different menus,
  1181. including the 'elec' menu (from the elecCompletions package).
  1182.  
  1183. ===============================================================================
  1184.  
  1185.            Package testing
  1186.  
  1187. The 'alpha::package' command is very similar to Tcl 8.0's standard
  1188. 'package' command, but differs in a few respects.  When Alpha upgrades
  1189. to Tcl 8, this will allow both features to coexist happily.  You can use
  1190. 'alpha::package' to check/request the presence of other packages.
  1191.  
  1192.     alpha::package require NAME ?VERSION?
  1193.     
  1194. Other sub-commands are 'exists' 'names' 'versions' 'vcompare' 'vsatisfies'
  1195. 'forget' 'uninstall' and 'mode', 'menu' and 'package'.  These last three
  1196. mimic the usual alpha::mode alpha::menu and alpha::package commands.
  1197.  
  1198.     alpha::package require ?-extension -mode -menu? name version
  1199.     alpha::package exists ?-extension -mode -menu? name version
  1200.     alpha::package names
  1201.     alpha::package uninstall name version [this-file|this-directory|script]
  1202.     alpha::package vcompare v1 v2
  1203.     alpha::package vsatisfies v1 v2
  1204.     alpha::package versions ?-extension -mode -menu? name
  1205.     alpha::package type name
  1206.     alpha::package info name
  1207.     alpha::package maintainer name version {name email web-page}
  1208.     alpha::package help name version [file 'name'|text]
  1209.  
  1210. Equivalent to alpha::mode, alpha::menu and alpha::extension
  1211.  
  1212.     alpha::package mode ...
  1213.     alpha::package menu ...
  1214.     alpha::package extension ...
  1215.  
  1216. For extensions only:
  1217.  
  1218.     alpha::package forget name version
  1219.  
  1220. ..
  1221.  
  1222. ===============================================================================
  1223.  
  1224.            Installation
  1225.  
  1226. There is a new install mode 'Inst' which adds the Install menu.
  1227. Install mode is trigerred when a file's name ends in 'Install'
  1228. or 'INSTALL', or when the first line of the file contains the
  1229. letters 'install', provided in this last case, that the file
  1230. is not in Alpha's Tcl hierarchy.  This last case is useful so
  1231. that a single .tcl file can be a package and be installed by
  1232. Alpha using these nice scripts, without the need for a separate
  1233. install-script-file.  However once that .tcl file is installed,
  1234. if you open it you certainly wouldn't want it opened in Install mode!
  1235.     
  1236. So, single file packages should just include 'install' somewhere in
  1237. their first line.  Multi-file packages should include an install
  1238. file.  Call this file 'OPEN TO INSTALL' or something like that.
  1239. When the user opens it, Inst mode is activated, and the user can
  1240. use the install menu to install your package.  If you wish the
  1241. installation dialog to be activated automatically, include the
  1242. text (auto-install) in the first line of the file.
  1243.  
  1244. Most packages will _not_ need anything other than the existence of
  1245. such a file.  In fact a file called 'OPEN TO INSTALL' containing the
  1246. single line '(auto-install)' will do the trick nicely.
  1247.  
  1248. Alpha will scan the installation file directory and make a nice
  1249. dialog with 'Easy install' and 'Custom install' options.  Alpha
  1250. knows where Modes, Menus, Completions, Bug fixes, Tools, Packages,
  1251. Extensions, ... all go in the Alpha hierarchy.
  1252.  
  1253. In summary:
  1254.  
  1255. (1) If it's a single file package (e.g. smartPaste.tcl), simply include
  1256. '(auto-install)' in the first line of the file, and when the file is
  1257. opened Alpha will try to install it.
  1258.  
  1259. (2) If it's a multi-file package, create a file 'OPEN TO INSTALL'
  1260. containing a single line containing the text '(auto-install)' and place it
  1261. in the same directory as your other files.  When the user opens that file,
  1262. they'll get a nice installation dialog.  (You can also change its type to
  1263. 'InSt' if you have resedit to get a nice icon).
  1264.  
  1265. More sophisticated things are possible, but usually not needed.  Note that
  1266. if you want to read an install file, rather than execute it, hold down
  1267. 'option' when you double click on it.
  1268.  
  1269. Finally, in most cases, simply dropping files into Alpha's directory
  1270. hierarchy will work (and Alpha will notice they are there and rebuild
  1271. indices etc automatically).  However if a user is upgrading, rather than
  1272. installing such a package for the first time, Alpha will not notice the
  1273. change and not rebuild indices and this will probably cause problems.  
  1274. Hence this is not a recommended installation technique.
  1275.  
  1276.              Package-specific installation over-rides
  1277.  
  1278. You can over-ride the default behaviour by providing a 'xxx_install.tcl'
  1279. file in the file directory.  In such a case that file will be sourced.
  1280. See "install.tcl" for some more information on how to over-ride the
  1281. default behaviour.  You will usually use the following procedure:
  1282.  
  1283.     install::packageInstallationDialog 'NAME' 'DESCRIPTION' ...
  1284.  
  1285. Optional arguments are as follows:
  1286.  
  1287.     -ignore {list of files to ignore}
  1288.     -remove {list of files to remove from Alpha hierarchy}    
  1289.     -forcequit '0 or 1'  
  1290.         (forces the user to quit; default 0)
  1291.     -require {Pkg version Pkg version ╔}
  1292.         e.g. -require {Alpha 7.0b1p2 elecCompletions 7.99}
  1293.     -provide {Pkg version Pkg version ╔}
  1294.  
  1295. and 
  1296.  
  1297.     -SystemCode -Modes -Menus -BugFixes -Completions -Packages
  1298.     -ExtensionsCode -UserModifications -Tools -Home
  1299.  
  1300. which force the placement/use of the following lists of files.  To
  1301. require an exact package version use:
  1302.  
  1303.     -require {Alpha {-exact 7.0b2} elecCompletions {-exact 8.1.2} ...}
  1304.  
  1305. Also, rather than having separate 'OPEN-TO-INSTALL' and '*install.tcl'
  1306. files, if the former file contains the text 'auto-install-script' in
  1307. its first line, it will be used as a Tcl script, and sourced rather than
  1308. opened.  Ensure that first line begins with a '#' or an error will
  1309. result.  (You can open that file for editing, without triggering the
  1310. install script if you hold down a modifier key).
  1311.  
  1312. If you gave the -provide option, Alpha checks those items with what
  1313. the user has already installed and warns if an item has already been 
  1314. installed and is not older than the one about to be installed.
  1315.  
  1316.              Uninstalling packages
  1317.  
  1318. Each package should provide a 'alpha::package uninstall name version script' 
  1319. statement.  When your script is evaluated, the global variable 'pkg_file' 
  1320. will be initialised to the full name of the file which contains the 
  1321. uninstall command.  Therefore for a single file package, the following is 
  1322. normal:
  1323.  
  1324.     alpha::package uninstall developerUtilities 1.1 {removeFile $pkg_file}
  1325.  
  1326. However, a much more convenient form of the above command is also possible, 
  1327. and most packages use it --- you may combine declaration and uninstall lines 
  1328. like this:
  1329.  
  1330.     alpha::extension developerUtilities 1.1 {
  1331.         # declaration script
  1332.     } uninstall {
  1333.         # uninstall script
  1334.     }
  1335.     
  1336. i.e. there are two extra optional arguments to the 'package' command.
  1337. Finally to be even simpler, if the command is 'uninstall this-file',
  1338. then that is equivalent to {removeFile $pkg_file}, and if the command
  1339. is 'uninstall this-directory', then that entire file's directory is
  1340. removed.  Make sure you don't use 'uninstall this-directory' for a
  1341. single-file package, or you'll wipe out the entire package hierarchy.
  1342. Similarly alpha::mode and alpha::menu commands may contain an optional
  1343. uninstall script like the above.
  1344.  
  1345.              Disabling packages
  1346.  
  1347. A package can add a script to be evaluated when the user disables the
  1348. package.  You do that with the additional command 'disable':
  1349.  
  1350.     alpha::extension developerUtilities 1.1 {
  1351.         # declaration script
  1352.     } disable {
  1353.         # disable script
  1354.     }
  1355.  
  1356. Complex packages will probably not provide such a script.  In such a
  1357. case the user would have to restart Alpha to disable the package
  1358. correctly.
  1359.  
  1360.              Tcl index files
  1361.  
  1362. You probably know that Tcl uses 'index' files to find procedures which
  1363. are called but not yet defined.  Your installation directories may
  1364. contain index files if you desire, but they are only installed if no
  1365. current index file exists in the installation location.  You cannot
  1366. override this behaviour.
  1367.  
  1368. ===============================================================================
  1369.            
  1370.            Vince's Additions Support:
  1371.  
  1372. This is primarily for new modes. 
  1373.  
  1374.              Source-Header files
  1375.      
  1376. If your mode makes distinctions between 'Source' and 'Header' 
  1377. files, you should define these two variables
  1378.  
  1379.     newPref var sourceSuffices { .cc .cp .cpp .c .icc } C++
  1380.     newPref var headerSuffices { .h .hh } C++
  1381.  
  1382.              Completions
  1383.  
  1384. If you mode is to use a variety of completion routines, define
  1385. an array entry like this:
  1386.  
  1387.     set completions(${mode}) \
  1388.         {completion::cmd completion::electric completion::word}
  1389.  
  1390. For the meaning of the list items, look at "elecCompletion.tcl".  If
  1391. all you need is the basic 'Command', 'Electric' and 'Word' completion
  1392. routines, the above list will do the trick.  You will then need to
  1393. define a variable ${mode}cmds like this:  
  1394.  
  1395.     set Ccmds { #elseif #endif #include class default enum for register return 
  1396.      struct switch typedef volatile while }
  1397.  
  1398. It MUST be in alphabetical order.  For electric template insertions, you need
  1399. to create an array with entries like these:
  1400.     
  1401.     set Celectrics(for) " (ÑinitÑ;ÑtestÑ;ÑincrementÑ)\{\n\tÑloop bodyÑ\n\}\nÑÑ"
  1402.     set Celectrics(while) " (ÑtestÑ)\{\n\tÑloop bodyÑ\n\}\nÑÑ"
  1403.     set Celectrics(switch) " (ÑvalueÑ)\{\n╔case ÑitemÑ:\n\tÑcase bodyÑ\n╔default:\n\tÑdefault bodyÑ\n\}\nÑÑ"
  1404.     set Celectrics(case) " ÑitemÑ:\n╔Ñcase bodyÑ\ncase"
  1405.  
  1406.              Mode-specific completions
  1407.  
  1408. If your mode has its own completion routines, they must be named
  1409. ${mode}::Completion::Type, where 'Type' is an entry in the above
  1410. list.  You'll have to know a reasonable bit of Tcl to write your
  1411. own routines like that.  Look at C::Completion::Class for a relatively
  1412. simple example.
  1413.  
  1414.              Electric menu templates
  1415.  
  1416. ${mode}Templates is a list of names which are added to the electric 
  1417. menu's 'Templates' sub-menu.  The real procs should be called 
  1418. 'file::${name}'.
  1419.  
  1420.              Vince's Additions summary
  1421.  
  1422. That's it!  Take a look at "scilabMode.tcl" as a simple example of a new mode
  1423. which makes use of Vince's Additions.
  1424.  
  1425. ===============================================================================
  1426.  
  1427.